<%--
  Created by IntelliJ IDEA.
  User: 86150
  Date: 2022/3/14
  Time: 09:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <%--<blockquote class="layui-elem-quote layui-text">--%>
        <%--鉴于小伙伴的普遍反馈，先温馨提醒两个常见“问题”：1. <a href="/doc/base/faq.html#form" target="_blank">为什么select/checkbox/radio没显示？</a> 2. <a href="/doc/modules/form.html#render" target="_blank">动态添加的表单元素如何更新？</a>--%>
        <%--</blockquote>--%>
        <form class="layui-form" action="" lay-filter="roleForm">
            <div class="layui-form-item">
                <label class="layui-form-label">职位：</label>
                <div class="layui-input-block" id="role">
                    <%--<input type="checkbox" name="roles[0].id" title="超级管理员" value="1">--%>
                    <%--<input type="checkbox" name="roles[1].id" title="管理员" value="2">--%>
                    <%--<input type="checkbox" name="roles[2].id" title="售票员" value="3">--%>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" name="id">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate,
            $=layui.$
        ;

        $(function () {
            $.get("role/listData.do",function (data) {
                var i=0;
                $(data.data).each(function () {


                    $("#role").append("<input type=\"checkbox\" name=\"roles["+i+"].id\" title=\""+this.name+"\" value=\""+this.id+"\">")
                    i++;
                })
                form.render('checkbox');

            })
        })

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        //监听提交
        form.on('submit(demo1)', function (data) {
            console.info(data.field)

            $.get("user/addRole.do",data.field,function (data) {
                if(data.success){
                    //关闭界面
                    layer.closeAll();


                }else{
                    layer.msg(data.error);
                }

            },"json")
            // table.reload('userTable')
            return false;
        });

    });
</script>

